import { dialogForm, DialogFormOptions } from "@/utils/dialogForm";
import ContractEdit from "../components/ContractEdit.vue";
import AgvTypeEdit from "../components/AgvTypeEdit.vue";

import { getListAllUser } from "@/api/modules/sys";
import { getCompanyList } from "@/api/modules/customer";
import { getProjectListCodeAll } from "@/api/modules/project";
import { getOrderDetail, getOrderReapproval } from "@/api/modules/order";
import { generateUUID } from "@/utils";

import { useDict } from "@/hooks/useDict";
import { useAddress } from "@/hooks/useAddress";
import { ORDER } from "@/constants";
import { h, ref, inject } from "vue";

const initTransForm = async (id: any, getDictId: any) => {
  let { data } = (await getOrderDetail({ id })) as any;

  // 合同标的
  data.productCategoryList = data.productCategoryList.map((item: any) => {
    item.uuid = generateUUID();
    return item;
  });
  data.supportingHardware = [];
  data.orderMaterielList.map((item: any) => {
    if (item.remark == getDictId("supportingHardware")) {
      data.supportingHardware.push({ uuid: generateUUID(), ...item });
    }
  });
  data.softwareSystems = [];
  data.orderMaterielList.map((item: any) => {
    if (item.remark == getDictId("softwareSystems")) {
      data.softwareSystems.push({ uuid: generateUUID(), ...item });
    }
  });
  data.construction = [];
  data.orderMaterielList.map((item: any) => {
    if (item.remark == getDictId("construction")) {
      data.construction.push({ uuid: generateUUID(), ...item });
    }
  });
  data.serve = [];
  data.orderMaterielList.map((item: any) => {
    if (item.remark == getDictId("serve")) {
      data.serve.push({ uuid: generateUUID(), ...item });
    }
  });

  // 文件列表
  data.orderConfirmationForm = [];
  data.technicalAgreements = [];
  data.planningScheme = [];
  data.layoutDrawing = [];
  // 处理文件默认值
  data.project.fileModels.forEach((item: any, index: number) => {
    if (item.typeId == getDictId("projectOrderConfirmationForm")) {
      data.orderConfirmationForm.push({
        originalFileName: item.name,
        path: item.path,
        name: item.name,
        status: "preview",
        uploadedSize: 0,
        progress: 1000,
        md5: index + 1,
        uid: index + 1
      });
    }
  });
  data.project.fileModels.forEach((item: any, index: number) => {
    if (item.typeId == getDictId("technicalAgreements")) {
      data.technicalAgreements.push({
        originalFileName: item.name,
        path: item.path,
        name: item.name,
        status: "preview",
        uploadedSize: 0,
        progress: 1000,
        md5: index + 1,
        uid: index + 1
      });
    }
  });
  data.project.fileModels.forEach((item: any, index: number) => {
    if (item.typeId == getDictId("planYourScenario")) {
      data.planningScheme.push({
        originalFileName: item.name,
        path: item.path,
        name: item.name,
        status: "preview",
        uploadedSize: 0,
        progress: 1000,
        md5: index + 1,
        uid: index + 1
      });
    }
  });
  data.project.fileModels.forEach((item: any, index: number) => {
    if (item.typeId == getDictId("bomList")) {
      data.layoutDrawing.push({
        originalFileName: item.name,
        path: item.path,
        name: item.name,
        status: "preview",
        uploadedSize: 0,
        progress: 1000,
        md5: index + 1,
        uid: index + 1
      });
    }
  });

  // 方案
  data.planUserId = data.project.userModels.find((item: any) => item.typeId == getDictId("planHead"))?.userId;

  // 地址
  if (data.project.countryName === "中国") {
    data.addressed = data.project.provinceCode
      ? [data.project.provinceCode, data.project.cityCode, data.project.districtCode].filter(item => item && item.trim())
      : [];
  }

  return data;
};
export const useEdit = (options: any) => {
  const mainTableRef: any = inject("mainTableRef");
  const { id, callback } = options;
  const { promise, getDictId } = useDict(["orderType", "industry", "customerType", "scenario", "shippingMethod"]);
  const { countryList, areaList, defaultOptions, promise: addressPromise } = useAddress();
  const config = ref({});
  const listAllUser = ref<any>([]);
  const dictList = ref<any>([]);
  const companyList = ref<any>([]);
  const getProjectListCodeAllList = ref<any>([]);

  const openDialog = async () => {
    await getDataInit();

    // 初始化
    const originData: any = await initTransForm(id, getDictId);
    config.value = {
      title: "编辑订单审核",
      width: 80,
      height: "80vh",
      form: {
        formData: {
          projectId: originData.project.id,
          id: originData.id,
          name: originData.name,
          code: originData.code,
          linkOrderId: originData.linkOrderId,
          orderTypeId: originData.orderTypeId,
          companyId: originData.companyId,
          companyName: originData.companyName,
          companyFinalId: originData.companyFinalId,
          companyFinalName: originData.companyFinalName,
          orderTime: originData.orderTime,
          deliveryTypeId: originData.deliveryTypeId,
          deliveryLocation: originData.deliveryLocation,
          mechanicalDesignNumber: originData.mechanicalDesignNumber,
          // planPurchaseTime: originData.planPurchaseTime,
          // planMechanicalDesignTime: originData.planMechanicalDesignTime,
          // planBomTime: originData.planBomTime,
          // planElectricalSchematicsTime: originData.planElectricalSchematicsTime,
          // planWiringDiagramTime: originData.planWiringDiagramTime,
          // planProductionCompletedTime: originData.planProductionCompletedTime,
          // planCustomSoftwareDevelopmentTime: originData.planCustomSoftwareDevelopmentTime,
          // planDebugCompletedTime: originData.planDebugCompletedTime,
          planDeliveryTime: originData.planDeliveryTime,
          purchaseTime: originData.purchaseTime,
          mechanicalDesignTime: originData.mechanicalDesignTime,
          bomTime: originData.bomTime,
          electricalSchematicsTime: originData.electricalSchematicsTime,
          wiringDiagramTime: originData.wiringDiagramTime,
          productionCompletedTime: originData.productionCompletedTime,
          customSoftwareDevelopmentTime: originData.customSoftwareDevelopmentTime,
          debugCompletedTime: originData.debugCompletedTime,
          deliveryTime: originData.deliveryTime,
          purchaseDelay: originData.purchaseDelay,
          purchaseDelayTime: originData.purchaseDelayTime,
          mechanicalDesignDelay: originData.mechanicalDesignDelay,
          mechanicalDesignDelayTime: originData.mechanicalDesignDelayTime,
          bomDelay: originData.bomDelay,
          bomDelayTime: originData.bomDelayTime,
          electricalSchematicsDelay: originData.electricalSchematicsDelay,
          electricalSchematicsDelayTime: originData.electricalSchematicsDelayTime,
          wiringDiagramDelay: originData.wiringDiagramDelay,
          wiringDiagramDelayTime: originData.wiringDiagramDelayTime,
          productionCompletedDelay: originData.productionCompletedDelay,
          productionCompletedDelayTime: originData.productionCompletedDelayTime,
          customSoftwareDevelopmentDelay: originData.customSoftwareDevelopmentDelay,
          customSoftwareDevelopmentDelayTime: originData.customSoftwareDevelopmentDelayTime,
          debugCompletedDelay: originData.debugCompletedDelay,
          debugCompletedDelayTime: originData.debugCompletedDelayTime,
          deliveryDelay: originData.deliveryDelay,
          deliveryDelayTime: originData.deliveryDelayTime,
          orderDelay: originData.orderDelay,
          orderDelayTime: originData.orderDelayTime,
          contractCode: originData.contractCode,
          contractSignTime: originData.contractSignTime,
          saleUserId: originData.saleUserId,
          saleUserName: originData.saleUserName,
          planUserName: originData.planUserName,
          planUserId: originData.planUserId,
          stageId: originData.stageId,
          spStatus: undefined,
          orderStatus: originData.orderStatus,
          productCategoryList: originData.productCategoryList,
          orderMaterielList: [],
          supportingHardware: originData.supportingHardware, // 自定义配套硬件
          softwareSystems: originData.softwareSystems, // 自定义软件系统
          construction: originData.construction, // 自定义施工
          serve: originData.serve, // 自定义服务
          // other: [], // 自定义其他
          delayTime: originData.delayTime,
          province: originData.project.province,
          city: originData.project.city,
          industryId: originData.project.industryId,
          addressed: originData.addressed, // 自定义国内省市区
          sceneId: originData.project.sceneId,
          projectFilesList: [],
          orderConfirmationForm: originData.orderConfirmationForm, // 自定义订单确认表
          technicalAgreements: originData.technicalAgreements, // 自定义技术协议
          planningScheme: originData.planningScheme, // 自定义规划方案
          layoutDrawing: originData.layoutDrawing, // 自定义布局图
          projectUserList: undefined,
          orderFollowModel: undefined,
          projectCode: undefined,
          projectName: undefined,
          userId: undefined,
          userName: undefined,
          avatarUrl: undefined,
          description: undefined,
          projectTypeId: undefined,
          countryId: originData.project.countryId,
          countryName: originData.project.countryName,
          provinceCode: originData.project.provinceCode,
          cityCode: originData.project.cityCode,
          district: originData.project.district,
          districtCode: originData.project.districtCode,
          address: undefined,
          hardwareNonStandardId: undefined,
          hardwareContent: undefined,
          hardwareCycle: undefined,
          softwareNonStandardId: undefined,
          softwareContent: undefined,
          softwareCycle: undefined,
          agvCount: undefined,
          progress: undefined,
          progressId: undefined,
          projectStatus: undefined,
          statusDescription: undefined,
          projectPlanStartTime: undefined,
          projectPlanEndTime: undefined,
          projecrStartTime: undefined,
          projecrEndTime: undefined,
          typeId: originData.typeId,
          remark: originData.remark
        },
        rules: {
          name: [{ required: true, message: "请填写名称" }],
          typeId: [{ required: true, message: "请选择订单类型" }],
          contractCode: [{ required: true, message: "请填写合同编号" }],
          saleUserId: [{ required: true, message: "请选择销售人员" }],
          code: [{ required: true, message: "请填写订单编号" }],
          deliveryLocation: [{ required: true, message: "请填写交货地点" }],
          companyId: [{ required: true, message: "请选择" }],
          companyFinalId: [{ required: true, message: "请选择" }],
          planDeliveryTime: [{ required: true, message: "请选择" }],
          orderConfirmationForm: [{ required: true, message: "请选择" }],
          technicalAgreements: [{ required: true, message: "请选择" }],
          productCategoryList: [{ required: true, message: "必须添加一个车辆" }],
          countryId: [{ required: true, message: "请选择" }],
          addressed: [{ required: true, message: "请选择" }],
          city: [{ required: true, message: "请填写" }],
          industryId: [{ required: true, message: "请选择" }],
          sceneId: [{ required: true, message: "请选择" }],
          deliveryTypeId: [{ required: true, message: "请选择" }],
          orderTime: [{ required: true, message: "请选择" }],
          planUserId: [{ required: true, message: "请选择" }],
          contractSignTime: [{ required: true, message: "请选择" }],
          // planPurchaseTime: [{ required: true, message: "请选择" }],
          // planMechanicalDesignTime: [{ required: true, message: "请选择" }],
          // planBomTime: [{ required: true, message: "请选择" }],
          // planElectricalSchematicsTime: [{ required: true, message: "请选择" }],
          // planWiringDiagramTime: [{ required: true, message: "请选择" }],
          // planProductionCompletedTime: [{ required: true, message: "请选择" }],
          // planCustomSoftwareDevelopmentTime: [{ required: false, message: "请选择" }],
          // planDebugCompletedTime: [{ required: false, message: "请选择" }],
          dynamicWrite: [
            { required: true, message: "请填写" },
            {
              validator: (rule: any, value: any, callback: any) => {
                console.log(rule);
                if (value <= 0) {
                  callback(new Error("必须大于0"));
                } else {
                  callback();
                }
              },
              trigger: "blur"
            }
          ],
          dynamicSelect: [
            {
              required: true,
              message: "请选择"
            }
          ]

          // typeId: [{ required: true, message: "请选择问题类型" }],
          // title: [{ required: true, message: "请填写问题标题" }],
          // content: [{ required: true, message: "请填写问题内容" }],
          // questionImg: [{ required: true, message: "请上传问题图片" }]
        },
        attribute: {
          "label-suffix": ""
        }
      },
      api: getOrderReapproval,
      column: [
        {
          type: "group",
          title: "基本信息",
          direction: "",
          len: 4,
          layout: "grid",
          list: [
            {
              type: "input",
              key: "name",
              formItemAttribute: {
                label: "名称"
              },
              attributes: {
                placeholder: "请填写"
              }
            },
            {
              type: "select",
              key: "typeId",
              formItemAttribute: {
                label: "订单类型"
              },
              attributes: {
                placeholder: "请选择",
                options: dictList.value[getDictId("orderType")],
                multiple: false,
                filterable: true,
                clearable: true
              }
            },
            {
              type: "input",
              key: "code",
              formItemAttribute: {
                label: "订单编号"
              },
              attributes: {
                placeholder: "请填写",
                options: [],
                multiple: false,
                filterable: true,
                clearable: true
              }
            },
            {
              type: "input",
              key: "linkOrderId",
              formItemAttribute: {
                label: "关联订单编号"
              },
              attributes: {
                placeholder: "请填写",
                options: getProjectListCodeAllList.value,
                multiple: false,
                filterable: true,
                clearable: true
              },
              fieldNames: {
                label: "nameClone",
                value: "id"
              }
            },
            {
              type: "select",
              key: "companyId",
              formItemAttribute: {
                label: "直接客户"
              },
              attributes: {
                placeholder: "请选择",
                options: companyList.value,
                multiple: false,
                filterable: true,
                clearable: true,
                changeFn: (val: any, originConfig: any) => {
                  const country = companyList.value.find((item: any) => item.id === val);
                  originConfig.formData.companyName = country?.name;
                }
              }
            },
            {
              type: "select",
              key: "companyFinalId",
              formItemAttribute: {
                label: "终端客户"
              },
              attributes: {
                placeholder: "请选择",
                options: companyList.value,
                multiple: false,
                filterable: true,
                clearable: true,
                changeFn: (val: any, originConfig: any) => {
                  const country = companyList.value.find((item: any) => item.id === val);
                  originConfig.formData.companyFinalName = country?.name;
                }
              }
            },
            {
              type: "select",
              key: "countryId",
              formItemAttribute: {
                label: "应用国家"
              },
              attributes: {
                placeholder: "请选择",
                options: countryList,
                multiple: false,
                filterable: true,
                clearable: true,
                changeFn: (val: any, originConfig: any, configModel: any) => {
                  const country = countryList.value.find((item: any) => item.id === val);
                  originConfig.formData.countryName = country?.countryName;
                  originConfig.formData.addressed = [];
                  originConfig.formData.province = "";
                  originConfig.formData.city = "";
                  originConfig.formData.district = "";
                  originConfig.formData.provinceCode = "";
                  originConfig.formData.cityCode = "";
                  originConfig.formData.districtCode = "";
                  if (country && country.countryName === "中国") {
                    configModel.column[0].list.forEach((itm: any) => {
                      if (itm.key === "addressed") {
                        itm.attributes.disabled = false;
                        itm.isHidden = false;
                      }
                      if (itm.key === "city") {
                        itm.isHidden = true;
                      }
                    });
                  } else {
                    configModel.column[0].list.forEach((itm: any) => {
                      if (itm.key === "addressed") {
                        itm.attributes.disabled = true;
                        itm.isHidden = true;
                      }
                      if (itm.key === "city") {
                        itm.isHidden = false;
                      }
                    });
                  }
                }
              },
              fieldNames: {
                label: "countryName",
                value: "id"
              }
            },
            {
              type: "cascader",
              key: "addressed",
              formItemAttribute: {
                label: "应用城市"
              },
              attributes: {
                placeholder: "请选择",
                ref: "cascaderRef",
                options: areaList,
                clearable: true,
                disabled: !(originData.project.countryName === "中国"),
                props: defaultOptions.value,
                changeFn: (val: any, originConfig: any, configModel: any, cascaderRef: any) => {
                  let arrAddress = cascaderRef.getCheckedNodes();
                  let names = arrAddress[0]["pathLabels"];
                  originConfig.formData.province = names[0];
                  originConfig.formData.city = names[1];
                  originConfig.formData.district = names[2];
                  originConfig.formData.provinceCode = val[0];
                  originConfig.formData.cityCode = val[1];
                  originConfig.formData.districtCode = val[2];
                }
              },

              isHidden: !(originData.project.countryName === "中国")
            },
            {
              type: "input",
              key: "city",
              formItemAttribute: {
                label: "应用城市"
              },
              attributes: {
                placeholder: "请填写",
                clearable: true
              },

              isHidden: originData.project.countryName === "中国"
            },

            // {
            //   type: "select",
            //   key: "province",
            //   formItemAttribute: {
            //     label: "应用省份"
            //   },
            //   attributes: {
            //     placeholder: "请选择",
            //     options: [],
            //     multiple: false,
            //     filterable: true,
            //     clearable: true
            //   }
            // },
            // {
            //   type: "select",
            //   key: "city",
            //   formItemAttribute: {
            //     label: "应用城市"
            //   },
            //   attributes: {
            //     placeholder: "请选择",
            //     options: [],
            //     multiple: false,
            //     filterable: true,
            //     clearable: true
            //   }
            // },
            {
              type: "select",
              key: "industryId",
              formItemAttribute: {
                label: "应用行业"
              },
              attributes: {
                placeholder: "请选择",
                options: dictList.value[getDictId("industry")],
                multiple: false,
                filterable: true,
                clearable: true
              }
            },
            {
              type: "select",
              key: "sceneId",
              formItemAttribute: {
                label: "应用场景"
              },
              attributes: {
                placeholder: "请选择",
                options: dictList.value[getDictId("scenario")],
                multiple: false,
                filterable: true,
                clearable: true
              }
            },
            {
              type: "select",
              key: "deliveryTypeId",
              formItemAttribute: {
                label: "发货方式"
              },
              attributes: {
                placeholder: "请选择",
                options: dictList.value[getDictId("shippingMethod")],
                multiple: false,
                filterable: true,
                clearable: true
              }
            },
            {
              type: "input",
              key: "contractCode",
              formItemAttribute: {
                label: "合同编号"
              },
              attributes: {
                placeholder: "请填写",
                clearable: true
              }
            },
            {
              type: "date-picker",
              key: "contractSignTime",
              formItemAttribute: {
                label: "合同签订日期"
              },
              attributes: {
                type: "date",
                placeholder: "请选择",
                format: "YYYY-MM-DD",
                valueFormat: "YYYY-MM-DD HH:mm:ss"
              }
            },
            {
              type: "date-picker",
              key: "planDeliveryTime",
              formItemAttribute: {
                label: "发货日期"
              },
              attributes: {
                type: "date",
                placeholder: "请选择",
                format: "YYYY-MM-DD",
                valueFormat: "YYYY-MM-DD HH:mm:ss"
              }
            },
            {
              type: "input",
              key: "deliveryLocation",
              formItemAttribute: {
                label: "交货地点"
              },
              attributes: {
                placeholder: "请填写"
              }
            },
            {
              type: "date-picker",
              key: "orderTime",
              formItemAttribute: {
                label: "下单日期"
              },
              attributes: {
                type: "date",
                placeholder: "请选择",
                format: "YYYY-MM-DD",
                valueFormat: "YYYY-MM-DD HH:mm:ss"
              }
            },
            {
              type: "select",
              key: "saleUserId",
              formItemAttribute: {
                label: "销售"
              },
              attributes: {
                placeholder: "请选择",
                options: listAllUser.value,
                multiple: false,
                filterable: true,
                clearable: true,
                changeFn: (val: any, originConfig: any) => {
                  const country = listAllUser.value.find((item: any) => item.id === val);
                  originConfig.formData.saleUserName = country?.name;
                }
              }
            },
            {
              type: "select",
              key: "planUserId",
              formItemAttribute: {
                label: "规划设计"
              },
              attributes: {
                placeholder: "请选择",
                options: listAllUser.value,
                multiple: false,
                filterable: true,
                clearable: true,
                changeFn: (val: any, originConfig: any) => {
                  const country = listAllUser.value.find((item: any) => item.id === val);
                  originConfig.formData.planUserName = country?.name;
                }
              }
            }
          ]
        },
        {
          type: "input",
          key: "remark",
          formItemAttribute: {
            label: "备注"
          },
          attributes: {
            placeholder: "请填写"
          }
        },
        // {
        //   type: "group",
        //   title: "订单计划",
        //   direction: "",
        //   len: 4,
        //   layout: "grid",
        //   list: [
        //     {
        //       type: "date-picker",
        //       key: "planPurchaseTime",
        //       formItemAttribute: {
        //         label: "预采清单下发"
        //       },
        //       attributes: {
        //         type: "date",
        //         placeholder: "请选择",
        //         format: "YYYY-MM-DD",
        //         valueFormat: "YYYY-MM-DD HH:mm:ss"
        //       }
        //     },
        //     {
        //       type: "date-picker",
        //       key: "planMechanicalDesignTime",
        //       formItemAttribute: {
        //         label: "机械图纸下发"
        //       },
        //       attributes: {
        //         type: "date",
        //         placeholder: "请选择",
        //         format: "YYYY-MM-DD",
        //         valueFormat: "YYYY-MM-DD HH:mm:ss"
        //       }
        //     },
        //     {
        //       type: "date-picker",
        //       key: "planBomTime",
        //       formItemAttribute: {
        //         label: "BOM下发"
        //       },
        //       attributes: {
        //         type: "date",
        //         placeholder: "请选择",
        //         format: "YYYY-MM-DD",
        //         valueFormat: "YYYY-MM-DD HH:mm:ss"
        //       }
        //     },
        //     {
        //       type: "date-picker",
        //       key: "planElectricalSchematicsTime",
        //       formItemAttribute: {
        //         label: "电气原理图"
        //       },
        //       attributes: {
        //         type: "date",
        //         placeholder: "请选择",
        //         format: "YYYY-MM-DD",
        //         valueFormat: "YYYY-MM-DD HH:mm:ss"
        //       }
        //     },
        //     {
        //       type: "date-picker",
        //       key: "planWiringDiagramTime",
        //       formItemAttribute: {
        //         label: "线束图下发"
        //       },
        //       attributes: {
        //         type: "date",
        //         placeholder: "请选择",
        //         format: "YYYY-MM-DD",
        //         valueFormat: "YYYY-MM-DD HH:mm:ss"
        //       }
        //     },
        //     {
        //       type: "date-picker",
        //       key: "planProductionCompletedTime",
        //       formItemAttribute: {
        //         label: "制造完成入库"
        //       },
        //       attributes: {
        //         type: "date",
        //         placeholder: "请选择",
        //         format: "YYYY-MM-DD",
        //         valueFormat: "YYYY-MM-DD HH:mm:ss"
        //       }
        //     },
        //     {
        //       type: "date-picker",
        //       key: "planCustomSoftwareDevelopmentTime",
        //       formItemAttribute: {
        //         label: "定制开发（可选）"
        //       },
        //       attributes: {
        //         type: "date",
        //         placeholder: "请选择",
        //         format: "YYYY-MM-DD",
        //         valueFormat: "YYYY-MM-DD HH:mm:ss"
        //       }
        //     },
        //     {
        //       type: "date-picker",
        //       key: "planDebugCompletedTime",
        //       formItemAttribute: {
        //         label: "调试完成（可选）"
        //       },
        //       attributes: {
        //         type: "date",
        //         placeholder: "请选择",
        //         format: "YYYY-MM-DD",
        //         valueFormat: "YYYY-MM-DD HH:mm:ss"
        //       }
        //     }
        //   ]
        // },
        {
          type: "group",
          title: "合同标的",
          direction: "",
          len: 1,
          layout: "grid",
          list: [
            {
              type: "slot",
              key: "productCategoryList",
              formItemAttribute: {
                label: "整机"
              },
              attributes: {
                placeholder: "请填写"
              }
            },
            {
              type: "slot",
              key: "supportingHardware",
              formItemAttribute: {
                label: "配套硬件"
              },
              attributes: {
                placeholder: "请填写"
              }
            },
            {
              type: "slot",
              key: "softwareSystems",
              formItemAttribute: {
                label: "软件系统"
              },
              attributes: {
                placeholder: "请填写"
              }
            },
            {
              type: "slot",
              key: "construction",
              formItemAttribute: {
                label: "施工"
              },
              attributes: {
                placeholder: "请填写"
              }
            },
            {
              type: "slot",
              key: "serve",
              formItemAttribute: {
                label: "服务"
              },
              attributes: {
                placeholder: "请填写"
              }
            }
            // {
            //   type: "slot",
            //   key: "other",
            //   formItemAttribute: {
            //     label: "其他"
            //   },
            //   attributes: {
            //     placeholder: "请填写"
            //   }
            // }
          ]
        },
        // {
        //   type: "group",
        //   title: "审批流程",
        //   direction: "",
        //   len: 4,
        //   layout: "grid",
        //   list: [
        //     {
        //       type: "select",
        //       key: "stageId",
        //       formItemAttribute: {
        //         label: "审批流选择"
        //       },
        //       attributes: {
        //         placeholder: "请选择",
        //         options: [],
        //         multiple: false,
        //         filterable: true,
        //         clearable: true
        //       }
        //     }
        //   ]
        // },
        {
          type: "group",
          title: "订单资料",
          direction: "",
          len: 4,
          layout: "grid",
          list: [
            {
              type: "fileSlice",
              key: "orderConfirmationForm",
              formItemAttribute: {
                label: "订单确认表"
              },
              attributes: {
                "prefix-data": ORDER,
                "limit-number": 100,
                accept: "*",
                success: (data: any) => {
                  console.log(data);
                }
              }
            },
            {
              type: "fileSlice",
              key: "technicalAgreements",
              formItemAttribute: {
                label: "技术协议"
              },
              attributes: {
                "prefix-data": ORDER,
                "limit-number": 100,
                accept: "*",
                success: (data: any) => {
                  console.log(data);
                }
              }
            },
            {
              type: "fileSlice",
              key: "planningScheme",
              formItemAttribute: {
                label: "规划方案（选填）"
              },
              attributes: {
                "prefix-data": ORDER,
                "limit-number": 100,
                accept: "*",
                success: (data: any) => {
                  console.log(data);
                }
              }
            },
            {
              type: "fileSlice",
              key: "layoutDrawing",
              formItemAttribute: {
                label: "布局图（选填）"
              },
              attributes: {
                "prefix-data": ORDER,
                "limit-number": 100,
                accept: "*",
                success: (data: any) => {
                  console.log(data);
                }
              }
            }
          ]
        }
      ],
      transformData: (data: any) => {
        // 处理地址
        delete data.addressed;
        // 处理文件
        // orderConfirmationForm: [], // 自定义订单确认表
        // technicalAgreements: [], // 自定义技术协议
        // planningScheme: [], // 自定义规划方案
        // layoutDrawing: [], // 自定义布局图
        data.orderConfirmationForm.forEach((item: any) => {
          data.projectFilesList.push({
            typeId: getDictId("projectOrderConfirmationForm"),
            name: item.originalFileName,
            path: item.path,
            originalFileName: item.originalFileName
          });
        });
        data.technicalAgreements.forEach((item: any) => {
          data.projectFilesList.push({
            typeId: getDictId("technicalAgreements"),
            name: item.originalFileName,
            path: item.path,
            originalFileName: item.originalFileName
          });
        });
        data.planningScheme.forEach((item: any) => {
          data.projectFilesList.push({
            typeId: getDictId("planYourScenario"),
            name: item.originalFileName,
            path: item.path,
            originalFileName: item.originalFileName
          });
        });
        data.layoutDrawing.forEach((item: any) => {
          data.projectFilesList.push({
            typeId: getDictId("bomList"),
            name: item.originalFileName,
            path: item.path,
            originalFileName: item.originalFileName
          });
        });
        delete data.orderConfirmationForm;
        delete data.technicalAgreements;
        delete data.planningScheme;
        delete data.layoutDrawing;
        // 处理整车
        data.productCategoryList = data.productCategoryList.map((item: any) => {
          delete item.uuid;
          return item;
        });
        // 处理物料
        // orderMaterielList: [],
        // supportingHardware: [], // 自定义配套硬件
        // softwareSystems: [], // 自定义软件系统
        // construction: [], // 自定义施工
        // serve: [], // 自定义服务
        data.orderMaterielList = [...data.supportingHardware, ...data.softwareSystems, ...data.construction, ...data.serve];
        delete data.supportingHardware;
        delete data.softwareSystems;
        delete data.construction;
        delete data.serve;
        data.orderMaterielList = data.orderMaterielList.map((item: any) => {
          delete item.uuid;
          return item;
        });
        return data;
      },
      message: "订单编辑成功"
    };

    const options: DialogFormOptions = {
      config: config.value,
      closeCallback: () => {},
      slots: {
        productCategoryList: (props: any) => {
          return h(AgvTypeEdit, {
            list: props.scope["productCategoryList"],
            keysName: "productCategoryList",
            rules: config.value["form"].rules
          });
        },
        supportingHardware: (props: any) => {
          return h(ContractEdit, {
            list: props.scope["supportingHardware"],
            typeId: getDictId("supportingHardware"),
            rules: config.value["form"].rules,
            keysName: "supportingHardware"
          });
        },
        softwareSystems: (props: any) => {
          return h(ContractEdit, {
            list: props.scope["softwareSystems"],
            typeId: getDictId("softwareSystems"),
            rules: config.value["form"].rules,
            keysName: "softwareSystems"
          });
        },
        construction: (props: any) => {
          return h(ContractEdit, {
            list: props.scope["construction"],
            typeId: getDictId("construction"),
            rules: config.value["form"].rules,
            keysName: "construction"
          });
        },
        serve: (props: any) => {
          return h(ContractEdit, {
            list: props.scope["serve"],
            typeId: getDictId("serve"),
            rules: config.value["form"].rules,
            keysName: "serve"
          });
        }
        // other: (props: any) => {
        //   return h(ContractEdit, { list: props.scope["other"], typeId: getDictId("planYourScenario") });
        // }
      },
      successCallback: () => {
        callback && callback();
        mainTableRef.value.refresh();
      }
    };

    dialogForm(options);
  };
  // 获取全部用户
  const getListAllUserFn = async () => {
    const { data } = await getListAllUser();
    listAllUser.value = data;
  };
  // 获取全部公司
  const getCompanyListFn = async () => {
    const { data } = await getCompanyList();
    companyList.value = data || [];
  };
  // 查询全部项目编号和项目名称（包含老项目）
  const getProjectCodeListFn = async () => {
    const { data } = await getProjectListCodeAll();
    getProjectListCodeAllList.value =
      (data &&
        data.map((item: any) => {
          item.nameClone = item.code + "-" + item.name;
          return item;
        })) ||
      [];
  };
  // 数据获取
  const getDataInit = async () => {
    await Promise.all([getListAllUserFn(), getCompanyListFn(), getProjectCodeListFn()]);
    dictList.value = await promise;
    await addressPromise;
  };

  return {
    openDialog
  };
};
